package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Accident;
import cn.wolfcode.crm.query.AccidentQueryObject;
import cn.wolfcode.crm.query.AccidentQueryObjectForGuaranteeBill;
import cn.wolfcode.crm.service.IAccidentService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import cn.wolfcode.crm.util.PermissionName;
import com.alibaba.fastjson.JSON;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @program: crm
 * @description:
 * @author: Mr.chen
 * @create: 2018-07-07 22:06
 **/
@Controller
@RequestMapping("accident")
public class AccidentController {
    @Autowired
    private IAccidentService service;


    @RequestMapping("")
    @PermissionName("事故主页")
    @RequiresPermissions("accident:index")
    public String index() {
        return "accident/list";
    }

    @RequestMapping("list")
    @ResponseBody
    @RequiresPermissions("accident:list")
    @PermissionName("事故数据")
    public PageResult list(AccidentQueryObject qo) {
        PageResult result = service.query(qo);

        return result;
    }

    @RequestMapping("list1")
    @ResponseBody
    @RequiresPermissions("accident:list1")
    @PermissionName("事故数据")
    public PageResult list1(AccidentQueryObject qo) {
        PageResult result = service.query1(qo);

        return result;
    }
    @RequestMapping("list2")
    @ResponseBody
    @RequiresPermissions("accident:list1")
    @PermissionName("事故数据")
    public PageResult list2(AccidentQueryObject qo) {
        PageResult result = service.query2(qo);

        return result;
    }
    @RequestMapping("list3")
    @ResponseBody
    @RequiresPermissions("accident:list3")
    @PermissionName("事故数据")
    public PageResult list3(AccidentQueryObject qo) {
        PageResult result = service.query3(qo);

        return result;
    }

    @RequestMapping("save")
    @ResponseBody
    @RequiresPermissions("accident:save")
    @PermissionName("事故保存")
    public JsonResult save(Accident entity) {
        JsonResult result = new JsonResult();
        try {
            service.save(entity);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("保存操作失败");
        }
        return result;
    }

    @RequestMapping("update")
    @ResponseBody
    @RequiresPermissions("accident:update")
    @PermissionName("事故更新")
    public JsonResult update(Accident entity) {
        JsonResult result = new JsonResult();
        try {
            service.update(entity);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("更新操作失败");
        }
        return result;
    }

    @RequestMapping("changeStatus")
    @ResponseBody
    @PermissionName("事故状态修改")
    public JsonResult changeStatus(Long id) {
        JsonResult result = new JsonResult();
        try {
            service.changeStatus(id);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("操作失败");
        }
        return result;
    }

    @RequestMapping("changeStatus1")
    @ResponseBody
    @PermissionName("事故状态修改")
    public JsonResult changeStatus1(Long id) {
        JsonResult result = new JsonResult();
        try {
            service.changeStatus1(id);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("操作失败");
        }
        return result;
    }
    @RequestMapping("changeStatus2")
    @ResponseBody
    @PermissionName("事故状态修改")
    public JsonResult changeStatus2(Long id) {
        JsonResult result = new JsonResult();
        try {
            service.changeStatus2(id);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("操作失败");
        }
        return result;
    }

    @RequestMapping("changeStatus3")
    @ResponseBody
    @PermissionName("事故状态修改")
    public JsonResult changeStatus3(Long id) {
        JsonResult result = new JsonResult();
        try {
            service.changeStatus3(id);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("操作失败");
        }
        return result;
    }


    @RequestMapping("changeStatus4")
    @ResponseBody
    @PermissionName("事故状态修改")
    public JsonResult changeStatus4(Long id) {
        JsonResult result = new JsonResult();
        try {
            service.changeStatus4(id);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("操作失败");
        }
        return result;
    }


    @RequestMapping("changeStatus5")
    @ResponseBody
    @PermissionName("事故状态修改")
    public JsonResult changeStatus5(Long id) {
        JsonResult result = new JsonResult();
        try {
            service.changeStatus5(id);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("操作失败");
        }
        return result;
    }

    @RequestMapping("selectForDuty")
    @ResponseBody
    public List<Map<String, String>> selectForDuty(String duty) {
        List<Map<String, String>> dutys = service.selectForDuty(duty);
        return dutys;
    }
    //查询保单信息在'客户理赔信息明细表'的dialog框中显示
    @RequestMapping("selectGuaranteeBillInfo")
    @ResponseBody
    public PageResult selectGuaranteeBillInfo(AccidentQueryObjectForGuaranteeBill qo) {
        PageResult result = service.selectGuaranteeBillInfo(qo);
        return result;
    }



    @RequestMapping("hasCom")
    @ResponseBody
    public JsonResult hasCom(Long id)
    {
        JsonResult result = new JsonResult();
        if (service.hasCom(id)){
            return result;
        }else{
            result = new JsonResult("操作失败");
            return result;
        }
    }



    @RequestMapping({"checklist"})
    public String checkView()
    {
        return "accident/checklist";
    }

    @RequestMapping({"payinfo"})
    public String payinfo()
    {
        return "accident/payinfo";
    }

    @RequestMapping({"paylist"})
    public String paylist()
    {
        return "accident/paylist";
    }

    @RequestMapping({"paylistbill"})
    public String paylistbill()
    {
        return "accident/paylistbill";
    }
}
